
#include <avr/io.h>
#include "adc.h"

void adc_init(void){
	
	//Write code to initialize the ADC.
	ADMUX |= (1<<MUX1) | (1<<MUX2) | (1<<REFS0) | (1<<REFS1); //Select ADC6
	ADCSRA |= (1<<ADEN);
	ADCSRA |= (1<<ADIE) | (1<<ADSC); //Enables interrupt when conversion completes & starts the conversion

}


ISR(ADC_vect) {
	uint16_t adc_value = ADC;
	//Process the information.
	char var_str[16];
	itoa(adc_value, var_str, 10);
	
	//Send it via uart.
	send_str(var_str);
	ADCSRA |= (1<<ADSC); //Restart conversion (perhaps not a good idea, dont know if main program run at all)
}